﻿using System.Data.Entity;
using StoreDemo.Domain.Data;

namespace StoreDemo.Data.Repository
{
    internal class EntityFrameworkUnitOfWork : IUnitOfWork
    {
        private readonly DbContext _context;

        public EntityFrameworkUnitOfWork(IDatabaseContextFactory databaseContextFactory)
        {
            _context = databaseContextFactory.CreateContext();
        }

        public IRepository<T> GetRepository<T>() where T : class
        {
            return new EntityFrameworkRepository<T>(_context);
        }

        public void Save()
        {
            _context.SaveChanges();
        }
    }
}